#!/usr/bin/env bash
#!/bin/sh
APP_NAME=maersk-gateway.jar
ENV_ACTIVE="dev"
JAVA_OPT="-Xms700m -Xmx1024m"
 
# ps -ef|grep quyan-eureka.jar|grep -v grep|grep -v kill | awk '{print $2}'

# ps -ef|grep maersk-gateway.jar|grep -v grep|grep -v kill | awk '{print $2}'

tpid=`ps -ef|grep $APP_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
if [ ${tpid} ]; then
echo 'Stop Process...'
kill -15 $tpid
fi
sleep 5
tpid=`ps -ef|grep $APP_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
if [ ${tpid} ]; then
echo 'Kill Process!'
kill -9 $tpid
else
echo 'Stop Success!'
fi
 
tpid=`ps -ef|grep $APP_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
if [ ${tpid} ]; then
    echo 'App is running.'
else
    echo 'App is NOT running.'
fi

rm -f tpid
nohup java ${JAVA_OPT} -jar $APP_NAME --spring.profiles.active=${ENV_ACTIVE} & tail -f nohup.out
echo $! > tpid
echo Start Success!


